#ifndef ANNO_ITEM_MANAGER_H
#define ANNO_ITEM_MANAGER_H
#include <qmap.h>
#include "osg/OsgAdapter.h"
#include "AnnoItem.h"
#include "script/ScriptHelper.h"

class AnnoItemManager : public IAnnoItemManager,public ScriptHelper
{
public:
	AnnoItemManager();
	~AnnoItemManager();
public:
    IAnnoItem* createItem(const QString& name,const QString& type,double lod = std::numeric_limits<double>::max());
	void setCurrentItem(const QString& name) 
	{
		auto item = getAnnoItemByName(name);
		if(item)
			currentItem = item;
	}
	void setCurrentItemAsNull(){currentItem = nullptr;}
	IAnnoItem* getCurrentItem()const { return currentItem; }
	void removeItem(const QString& name);
	QStringList getItemList()const { return annoItems.keys(); }
	IAnnoItem* getAnnoItemByName(const QString& name) 
	{
		auto itr = annoItems.find(name);
		if(itr == annoItems.end())
			return nullptr;
		return *itr;
	}
	int getItemCount() {return annoItems.size(); }
	void clear();
public:
    bool containProperty(const QString& key);
    void setProperty(const Property& property);
	void setProperty(const QString& name,const QString& value);
    Property getProperty(const QString& key)const;
    QStringList getPropertyNameList()const;

	void setItemTwinkle(bool enable);
    bool isItemTwinkle()const;
public:
	void setStyleName(const QString& name);
	QString getStyleName()const;
public:
	QString getModule()const { return "AnnoItemManager"; }

	bool createItem(const QStringList& argument,QString* error = nullptr);
	bool setCurrentItem(const QStringList& argument,QString* error = nullptr);
	bool setCurrentItemAsNull(const QStringList& argument,QString* error = nullptr);
	bool removeItem(const QStringList& argument,QString* error = nullptr);
	bool setProperty(const QStringList& argument,QString* error = nullptr);
	bool setStyleName(const QStringList& argument,QString* error = nullptr);
	bool clear(const QStringList& argument,QString* error = nullptr);

	bool setItemTwinkle(const QStringList& argument,QString* error = nullptr);
	bool loadCelestiaSscFile(const QStringList& argument,QString* error = nullptr);
private:
	IAnnoItem* currentItem = nullptr;
	QMap<QString,IAnnoItem*> annoItems;
	osg::Callback* twinkle = nullptr;
};

#endif
